package com.ncloud.crm.mapper;

import com.ncloud.crm.entity.BsDiscnt;
import org.apache.ibatis.annotations.*;

@Mapper
public interface BsDiscntMapper {
	
	@Insert("insert into bs_discnt(discnt_inst_id, discnt_id, discnt_name,prod_inst_id,prod_id,is_base, begin_date, end_date,create_time, create_user, update_time, update_user, remark)"
            + " values(#{discntInstId},#{discntId},#{discntName},#{prodInstId},#{prodId},#{isBase},#{beginDate},#{endDate},#{createTime},#{createUser},#{updateTime},#{updateUser},#{remark})")
	int insertBsDiscnt(BsDiscnt bsDiscnt);
	
	@Update("update bs_discnt set end_date=#{endDate},update_time=#{updateTime},"
			+ "update_user=#{updateUser},remark=#{remark} where discnt_inst_id=#{discntInstId} and begin_date = #{beginDate}")
	int updateBsDiscnt(BsDiscnt bsDiscnt);
	@Select(value = { "select * from bs_discnt where discnt_inst_id = #{discntInstId} and  now() between begin_date and end_date" })
	@Results({ @Result(column = "discnt_inst_id", property = "discntInstId"),
			@Result(column = "discnt_id", property = "discntId"),@Result(column = "discnt_name", property = "discntName"),
			@Result(column="prod_inst_id",property="prodInstId"),@Result(column="prod_id",property="prodId"),
			@Result(column="is_base",property="isBase"),@Result(column="begin_date",property="beginDate"),
			@Result(column="end_date",property="endDate"),@Result(column="update_time",property="updateTime"),
			@Result(column="update_user",property="updateUser"),@Result(column="node_sub_type",property="nodeSubType"),
			@Result(column="create_time",property="createTime"),@Result(column="create_user",property="createUser")})
	public BsDiscnt getBsDiscntByPk(Long discntId);
}